<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    
<title>mushpup jQuery unit testing template</title>

<!-- Stylesheets -->
    
<!-- Google AJAX Apis -->
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.0");
</script>

<!-- jQuery Unit Tests -->
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" type="text/css" media="screen" />

<script src="../js/external/paj/sha1.js"></script>
<script src="../js/external/parseUri.js"></script>
<script src="../js/external/jquery_plugins/jquery.corners.min.js"></script>
<script src="../js/mushpup/mushpup.js"></script>
<script src="http://mushpup.googlecode.com/svn/branches/version1/js_bin/mushpup/mushpup_algorithm.js"></script>
    

<!-- Unit Tests -->
<script type="text/javascript">
$(document).ready(function(){
    
    var Mushpup = new MushpupBase();

    module('MUSHPUP BASIC (version ' + Mushpup.version + ')');
    test('instantiation', function() {
        ok( Mushpup != undefined, 'Mushpup object exists' );
        ok( Mushpup.version != undefined, 'Mushpup.version = ' +  Mushpup.version);
        equals( Mushpup.is_loaded, 1, 'load test' );
    });
    
    test('sha testing', function() {
        equals( Mushpup.sha.hex('test'), 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', "sha.hex " );
        equals( Mushpup.sha.b64('test'), 'qUqP5cyxm6YcTAhz05Hph5gvu9M', "sha.b64" );
    });
    
    test('hash testing', function() {
        equals( Mushpup.hash_v1('test'), 'qUqP5cyxm6YcTAhz05Hph5gv', 'hash_v1' ); 
    });
    
    test('trim', function() {
        var s_ = '  untrimmed string  ';
        equals( Mushpup.ltrim(s_), 'untrimmed string  ', 'left trim' );
        equals( Mushpup.rtrim(s_), '  untrimmed string', 'right trim' );
        equals( Mushpup.trim(s_), 'untrimmed string', 'trim' );
    });
    
     
    module('MUSHPUP HASH MAPPINGS');
    test('test maps', function() {
        equals( Mushpup.paj_b64_map.length, 64, 'paj b64 map length');
        equals( Mushpup.paj_b64_map[0], 'A', 'paj b64 map 0-index');
        equals( Mushpup.paj_b64_map[63], '/', 'paj b64 map 63-index');
        
        equals( Mushpup.mushpup_map.length, 64, 'mushpup map map length');
        equals( Mushpup.mushpup_map[0], 'A', 'mushpup map 0-index');
        equals( Mushpup.mushpup_map[63], 'l', 'mushpup map 63-index');
        
        equals( Mushpup.alpha_map.length, 64, 'alpha map length');
        equals( Mushpup.number_map.length, 64, 'number map length');
        equals( Mushpup.symbol_map.length, 64, 'symbol map length');
    });
    
    test('map to array', function() {
        var MushpupMapDict = Mushpup.map_to_dict(Mushpup.mushpup_map);
        equals( MushpupMapDict['A'], 0, 'Mushpup.mushpup_map to Dict A-key');
        equals( MushpupMapDict['9'], 61, 'Mushpup.mushpup_map to Dict 9-index');
        equals( MushpupMapDict['!'], undefined, 'Mushpup.mushpup_map to Dict !-key');
        
        var SymbolMapDict = Mushpup.map_to_dict(Mushpup.symbol_map);
        equals( SymbolMapDict['A'], undefined, 'Mushpup.symbol_map to Dict A-key');
        equals( SymbolMapDict['9'], undefined, 'Mushpup.symbol_map to Dict 9-index');
        equals( SymbolMapDict['!'], 0, 'Mushpup.symbol_map to Dict ?-key');
        equals( SymbolMapDict[']'], 19, 'Mushpup.symbol_map to Dict ]-key');        
    });
    
    test('remapping', function() {
        equals( Mushpup.remap('ABC', 'symbol'), '!?@', 'map alphanum to symbol' );
        equals( Mushpup.remap('ABC', 'number'), '012', 'map alphanum to number' );
        equals( Mushpup.remap('!?@', 'alpha'), 'ABC', 'map symbol to alpha' );
        equals( Mushpup.remap('!?@', 'number'), '012', 'map symbol to number' );
        equals( Mushpup.remap('~`/', 'mushpup'), 'ABC', 'map unrecognized to mushpup' );
        equals( Mushpup.remap('~`/', 'number'), '012', 'map unrecognized to number' );
        equals( Mushpup.remap('~`/', 'symbol'), '!?@', 'map unrecognized to symbol' );
        equals( Mushpup.remap('A', 'symbol'), '!', 'map alpha to symbol' );
    });
    
    
    module('MUSHPUP URL PARSING');
    test('parseUri tests', function() {
        var uri = 'http://domain.com/user/modifiers/?key1=val1&key2=val2';
        var UriDict = Mushpup._parse_uri(uri);
        equals( UriDict['source'], uri, '_parse_uri source' );
        equals( UriDict['protocol'], 'http', '_parse_uri protocol' );
        equals( UriDict['authority'], 'domain.com', '_parse_uri authority' );
        equals( UriDict['host'], 'domain.com', '_parse_uri host' );
        equals( UriDict['path'], '/user/modifiers/', '_parse_uri path' );
        equals( UriDict['query'], 'key1=val1&key2=val2', '_parse_uri query' );
        equals( UriDict['queryKey']['key1'], 'val1', '_parse_uri queryKey' );
        equals( UriDict['queryKey']['key2'], 'val2', '_parse_uri queryKey' );
    });
    test('parseUri exceptions', function() {
        var uri = 'domain/user/a+!';
        var UriDict = Mushpup._parse_uri(uri);
        equals( UriDict['host'], 'domain', '_parse_uri host' );
        equals( UriDict['path'], '/user/a+!', '_parse_uri path' );
    });
    test('parse_url tests', function() {
        var url = 'http://domain.com/user/!+/?key1=val1';
        var UrlDict = Mushpup.parse_url(url);
        equals( UrlDict['raw'], 'http://domain.com/user/!+/?key1=val1', 'parse_url raw' );
        equals( UrlDict['url'], 'http://domain.com/user/!+/', 'parse_url url' );
        equals( UrlDict['domain'], 'domain.com', 'parse_url domain' );
        equals( UrlDict['PathList'][1], '!+', 'parse_url PathList 1' );
    });
    
    
    module('MUSHPUP LOCUS PARSING');
    test('string parsing tests', function() {
        var locus = 'site.com/user/a!+';
        var LocusList = locus.split('/');
        var locus_slice = locus.slice(1);
        equals( LocusList[0], 'site.com', 'locus sprint' );
        equals( locus_slice, 'ite.com/user/a!+', 'locus slice' );
    });
    test('mod parsing test', function() {
        var valid_mod_string = 'a+!';
        var invalid_mod_string = 'abc';
        var mutex_mod_string = 'Aa';
        equals( Mushpup.parse_mods(valid_mod_string).join(''),
                ['a','+','!'].join(''),
                'valid_mod_string' );
        equals( Mushpup.parse_mods(invalid_mod_string).join(''), '',
                'invalid_mod_string' );
        equals( Mushpup.parse_mods(mutex_mod_string).join(''), '',
                'mutex_mod_string' );
    });
    
    
    module('MUSHPUP HASH PANEL (version ' + Mushpup.UI.version + ')');
    test('load hash panel (this was failing on IE6)', function() {
        var expect = 'abcdefghijklmnopqrstuvwx';
        var $hashpanel = Mushpup.UI.build_hash_panel();
        var ChildList = jQuery.makeArray($hashpanel.children());
        ok( jQuery.inArray( $('#mp_ruler_block'), ChildList) );
    });
    test('build hash ruler (this was failing on IE6)', function() {
        var expect = 'abcdefghijklmnopqrstuvwx';
        $ruler = Mushpup.UI._build_ruler('test_ruler', expect);
        equals( $ruler.html().replace(/(<([^>]+)>)/ig, ''),
                expect,
                'confirm hash template' );
    });
    
    module('MUSHPUP V1 HASH REGRESSION');
    test('paj sha-1 hash test', function() {
        var b64_hash = b64_sha1('test');
        var hex_hash = hex_sha1('test');
        equals( b64_hash, 'qUqP5cyxm6YcTAhz05Hph5gvu9M', "b64_sha1('test')" );
        equals( hex_hash, 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', "hex_sha1('test')" );
    });
    test('test hash', function() {
        var plain = 'test';
        var expect = 'qUqP5cyxm6YcTAhz05Hph5gv';
        var test = mushpup_sha24(plain);
        equals( test, expect );
    });  
    
    
    module('MUSHPUP UI (version ' + Mushpup.UI.version + ')');
    test('load test', function() {
        equals( Mushpup.UI.load_test(), Mushpup.UI.version, 'simple UI test' );
    });
    
    test('Ctrl-C Callback (press Ctrl-C to test)', function() {
        var callback_ = function() { alert('Ctrl-C Callback called'); }
        Mushpup.UI.set_ctrlc_callback(callback_);
    });

});
  </script>
  
</head>
<body>

 <h1 id="qunit-header">Mushpup Unit Testing</h1>
 <h2 id="qunit-banner"></h2>
 <h2 id="qunit-userAgent"></h2>
 <ol id="qunit-tests"></ol>
 
 <div id="hidden_div" style="display:none;">
    you can use this for tests without disrupting display
 </div>
 
</body>
</html>
